﻿using Super.Hmi.ViewModels.Base;

namespace Super.Hmi.Models.User
{
    public class UserModel : ViewModelBase
    {
        /// <summary>
        /// 用户基础模型
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// 用户ID
        /// </summary>
        public int UserId { get; set; } = -1;
        /// <summary>
        /// 部门ID
        /// </summary>
        public int DepartmentId { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }
        /// <summary>
        /// 用户创建时间
        /// </summary>
        public string CreateTime { get; set; }
        /// <summary>
        /// 用户更新时间
        /// </summary>
        public string UpdateTime { get; set; }
        /// <summary>
        /// 最后登录时间
        /// </summary>
        public string? LastLoginTime { get; set; }
        /// <summary>
        /// 旧密码
        /// </summary>
        public string? OldPassword { get; set; }
        /// <summary>
        /// 确认密码
        /// </summary>
        public string? CheckPassword { get; set; }
        /// <summary>
        /// 个性签名
        /// </summary>
        public string? PersonalizedSignature { get; set; } // 个性签名
        private string _userName = "";
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName
        {
            get { return _userName; }
            set
            {
                SetProperty(ref _userName, value);
                ValidateContent();
            }
        }
        private int _gender;
        /// <summary>
        /// 性别
        /// </summary>
        public int Gender
        {
            get { return _gender; }
            set { SetProperty(ref _gender, value); }
        }
        private string _nickName;
        /// <summary>
        /// 用户昵称
        /// </summary>
        public string NickName
        {
            get { return _nickName; }
            set { SetProperty(ref _nickName, value); }
        }
        private string _email;
        /// <summary>
        /// 用户邮箱
        /// </summary>
        public string Email
        {
            get { return _email; }
            set { SetProperty(ref _email, value); }
        }
        private string _phone;
        /// <summary>
        /// 用户手机号码
        /// </summary>
        public string Phone
        {
            get => _phone;
            set => SetProperty(ref _phone, value);
        }
        private int _isActive;
        /// <summary>
        /// 是否启用用户
        /// </summary>
        public int IsActive
        {
            get => _isActive;
            set => SetProperty(ref _isActive, value);
        }
        private string _gravatar;
        /// <summary>
        /// 用户头像
        /// </summary>
        public string Gravatar
        {
            get { return _gravatar; }
            set
            {
                SetProperty(ref _gravatar, value);
            }
        }
        /// <summary>
        /// 用户显示工号和名称 防止名称一样
        /// </summary>
        public string UserIdAndUserName
        {
            get
            {
                if (UserId == -1) return "";
                return $"[{UserId}]{UserName}";
            }
        }
        /// <summary>
        /// 验证
        /// </summary>
        public override void ValidateContent()
        {
            #region AddUser.UserName
            if (string.IsNullOrEmpty(UserName))
            {
                AddError("用户名不能为空", nameof(UserName));
            }
            else ClearErrors(nameof(UserName));
            #endregion

            base.ValidateContent();
        }
    }
}
